﻿/*----------------------------------------------------------------
// Copyright (C) 2011 王冲
// 版权所有。 
//
// 文件名：TempCardInfoInfo
// 文件功能描述：临时卡资料维护业务逻辑层
//
// 
// 创建标识：2012-06-29
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DAO.WaiGaoQiao;

namespace Model.WaiGaoQiao
{
    public class TempCardInfoInfo
    {
        public int PID
        {
            get;
            set;
        }
        public string DeptName
        {
            get;
            set;
        }
        public int DEP_ID
        {
            get;
            set;
        }
        public string EMPNO
        {
            get;
            set;
        }
        public string PName
        {
            get;
            set;
        }
        public string CARDSTATUS
        {
            get;
            set;
        }
        public string CARDSERIAL
        {
            get;
            set;
        }
        public string Balance
        {
            get;
            set;
        }
        public string EnrollDate
        {
            get;
            set;
        }
        public int GroupIdDept
        {
            get;
            set;
        }
        public int structrueId
        {
            get;
            set;
        }
        public string GroupName
        {
            get;
            set;
        }
        public string StructrueName
        {
            get;
            set;
        }

        private DataAccessTempCardInfo dar;

        public TempCardInfoInfo()
        {
            dar = new DataAccessTempCardInfo();
        }

        /// <summary>
        /// 临时卡信息数量
        /// </summary>
        /// <returns></returns>
        public int GetCount(string where)
        {
            return dar.GetCount(where);
        }

        /// <summary>
        /// 获取部门列表（用于绑定下拉框）
        /// </summary>
        /// <returns></returns>
        public DataSet GetdeptName()
        {
            return dar.GetdeptName();
        }

        /// <summary>
        /// 获取临时卡信息表
        /// </summary>
        /// <returns></returns>
        public IList<TempCardInfoInfo> GetList(int pagesize, int startindex, string strquery)
        {
            IList<TempCardInfoInfo> perlist = new List<TempCardInfoInfo>();
            TempCardInfoInfo perinfo;
            DataSet ds = dar.GetList(pagesize, startindex, strquery);
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                perinfo = new TempCardInfoInfo()
                {
                    PID = Convert.ToInt32(item["PID"]),
                    DeptName = item["DeptName"].ToString(),
                    EMPNO = item["EMPNO"].ToString(),
                    PName = item["PName"].ToString(),
                    CARDSTATUS = item["卡状态"].ToString(),
                    CARDSERIAL = item["卡序列号"].ToString(),
                    Balance = item["卡内余额"].ToString(),
                    EnrollDate = item["入职日期"].ToString(),
                    GroupName = item["groupName"].ToString(),
                    StructrueName = item["岗位名称"].ToString()
                };
                perlist.Add(perinfo);
            }
            return perlist;
        }

        /// <summary>
        /// 根据编号获取一条临时人员信息
        /// </summary>
        /// <param name="supplierNo"></param>
        /// <returns></returns>
        public TempCardInfoInfo GetInfoOne(string id)
        {
            dar = new DataAccessTempCardInfo();
            DataSet ds = dar.GetInfoOne(id);
            TempCardInfoInfo info = new TempCardInfoInfo();
            info.PID = int.Parse(ds.Tables[0].Rows[0]["PID"].ToString());
            info.DeptName = ds.Tables[0].Rows[0]["DeptName"].ToString();
            info.EMPNO = ds.Tables[0].Rows[0]["EMPNO"].ToString();
            info.PName = ds.Tables[0].Rows[0]["PName"].ToString();
            info.CARDSTATUS = ds.Tables[0].Rows[0]["卡状态"].ToString();
            info.CARDSERIAL = ds.Tables[0].Rows[0]["卡序列号"].ToString();
            info.Balance = ds.Tables[0].Rows[0]["卡内余额"].ToString();
            info.EnrollDate = ds.Tables[0].Rows[0]["入职日期"].ToString();
            info.DEP_ID = Convert.ToInt32(ds.Tables[0].Rows[0]["DEP_ID"]);
            if (ds.Tables[0].Rows[0]["GroupIdDept"].ToString() != "")
            {
                info.GroupIdDept = Convert.ToInt32(ds.Tables[0].Rows[0]["GroupIdDept"]);
            }
            if (ds.Tables[0].Rows[0]["岗位编号"].ToString() != "")
            {
                info.structrueId = Convert.ToInt32(ds.Tables[0].Rows[0]["岗位编号"]);
            }
            return info;
        }

        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="car"></param>
        /// <returns></returns>
        public int SaveTempCardInfoEdit(TempCardInfoInfo car)
        {
            object[] objcar = new object[] { car.PID, car.PName, car.DEP_ID, car.EMPNO, car.GroupIdDept, car.structrueId };
            return dar.SaveTempCardInfoEdit(objcar);
        }

        public bool CheckEmpNo(int EmpNo, int PID)
        {
            int count = dar.CheckEmpNo(EmpNo, PID);
            return count > 0 ? false : true;
        }

        /// <summary>
        /// 获取岗位列表（用于绑定下拉框）
        /// </summary>
        /// <returns></returns>
        public DataSet GetStructrueName()
        {
            return dar.GetStructrueName();
        }
    }
}
